package miracle.joker.design.observer;

public class StatisticsDisplay implements Observer {
    private float temperatureSum = 0.0f;
    private float humiditySum = 0.0f;
    private int numReadings;

    public StatisticsDisplay(WeatherData weatherData) {
        weatherData.registerObserver(this);
    }

    public void update(float temperature, float humidity, float pressure) {
        temperatureSum += temperature;
        humiditySum += humidity;
        numReadings++;

        System.out.println("Avg temperature: " + (temperatureSum / numReadings) + "F degrees and Avg humidity: "
                + (humiditySum / numReadings) + "%");
    }
}
